﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StudentManagerPro.UserControls
{
    public partial class Query : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ddlClass.DataSource = new StudentClassService().GetStudentClass();
                this.ddlClass.DataTextField = "ClassName";
                this.ddlClass.DataValueField = "ClassId";
                this.ddlClass.DataBind();
            }
            this.ltaMsg.Text = "";
        }

        /// <summary>
        /// 查询：查询学员信息，也可以查询成绩信息：把当前要完成的任务交给一个事件去执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.ClassName = this.ddlClass.SelectedItem.Text.Trim();

            //3.调用
            if (queryEvent != null)
            {
                queryEvent();
            }

            if (queryEvent1 != null)
            {
                queryEvent1(this.ddlClass.SelectedItem.Text.Trim());
            }
        }
        //把班级定义成属性（和外交交互）
        public string ClassName { get; set; }

        //2.根据委托定义事件
        public event QueryDelegate queryEvent= null;
        public QueryDelegate1 queryEvent1 = null;

    }
    //1.定义委托
    public delegate void QueryDelegate();

    public delegate void QueryDelegate1(string className);
}